What is @walletconnect/utils?
@walletconnect/utils is a utility library for WalletConnect, providing various helper functions to facilitate the development of WalletConnect integrations. It includes utilities for encoding, decoding, and other common operations needed when working with WalletConnect.
What are @walletconnect/utils's main functionalities?
Encoding and Decoding
This feature allows you to encode and decode data, which is useful for transmitting data securely between clients and servers.
const { encode, decode } = require('@walletconnect/utils');
const data = 'Hello, WalletConnect!';
const encodedData = encode(data);
const decodedData = decode(encodedData);
console.log(encodedData); // Encoded data
console.log(decodedData); // 'Hello, WalletConnect!'
Hex Conversion
This feature provides functions to convert numbers to hexadecimal strings and vice versa, which is often needed in blockchain and cryptographic applications.
const { toHex, fromHex } = require('@walletconnect/utils');
const number = 255;
const hexString = toHex(number);
const numberFromHex = fromHex(hexString);
console.log(hexString); // '0xff'
console.log(numberFromHex); // 255
Random Bytes Generation
This feature allows you to generate random bytes, which can be used for creating secure keys or nonces.
const { generateRandomBytes } = require('@walletconnect/utils');
const randomBytes = generateRandomBytes(16);
console.log(randomBytes); // Random 16 bytes
Other packages similar to @walletconnect/utils
ethers
Ethers.js is a library for interacting with the Ethereum blockchain and its ecosystem. It provides utilities for encoding, decoding, and other cryptographic operations, similar to @walletconnect/utils, but with a broader focus on Ethereum-specific functionalities.
web3-utils
Web3-utils is a utility library that is part of the Web3.js suite. It offers various utilities for encoding, decoding, and other common operations needed when working with Ethereum. It is similar to @walletconnect/utils but is more focused on general Ethereum development.
crypto-js
Crypto-js is a library of cryptographic algorithms implemented in JavaScript. It provides utilities for encoding, decoding, and generating random bytes, similar to @walletconnect/utils, but with a broader range of cryptographic functionalities.
WalletConnect Utils
Utility Library for WalletConnect
API
function convertArrayBufferToBuffer (arrayBuffer: ArrayBuffer): Buffer
function convertArrayBufferToUtf8 (arrayBuffer: ArrayBuffer): string
function convertArrayBufferToHex (arrayBuffer: ArrayBuffer, noPrefix?: boolean): string
function convertArrayBufferToNumber (arrayBuffer: ArrayBuffer): number
function concatArrayBuffers (...args: ArrayBuffer[]): ArrayBuffer
function convertBufferToArrayBuffer (buffer: Buffer): ArrayBuffer
function convertBufferToUtf8 (buffer: Buffer): string
function convertBufferToHex (buffer: Buffer, noPrefix?: boolean): string
function convertBufferToNumber (buffer: Buffer): number
function concatBuffers (...args: Buffer[]): Buffer
function convertUtf8ToArrayBuffer (utf8: string): ArrayBuffer
function convertUtf8ToBuffer (utf8: string): Buffer
function convertUtf8ToHex (utf8: string, noPrefix?: boolean): string
function convertUtf8ToNumber (utf8: string): number
function convertNumberToBuffer (num: number): Buffer
function convertNumberToArrayBuffer (num: number): ArrayBuffer
function convertNumberToUtf8 (num: number): string
function convertNumberToHex (num: number, noPrefix?: boolean): string
function convertHexToBuffer (hex: string): Buffer
function convertHexToArrayBuffer (hex: string): ArrayBuffer
function convertHexToUtf8 (hex: string): string
function convertHexToNumber (hex: string): number
function sanitizeHex (hex: string): string
function addHexPrefix (hex: string): string
function removeHexPrefix (hex: string): string
function isHexString (value: any): boolean
function isEmptyString (value: string): boolean
function isEmptyArray (array: any[]): boolean
function payloadId (): number
function uuid (): string
function keccak256 (data?: string): string
function getMeta (): IClientMeta | null
function parseWalletConnectUri (str: string): IParseURIResult
function promisify (originalFn: (...args: any[]) => void, thisArg?: any): (...callArgs: any[])
function parsePersonalSign (params: string[]): string[]
function parseTransactionData (txData: Partial<ITxData>): Partial<ITxData>
function formatRpcError (error: Partial<IJsonRpcErrorMessage>): { code: number, message: string, data?: string}
function isJsonRpcSubscription (object: any): boolean
function isJsonRpcRequest (object: any): boolean
function isJsonRpcResponseSuccess (object: any): boolean
function isJsonRpcResponseError (object: any): boolean
function isInternalEvent (object: any): boolean
function isWalletConnectSession (object: any): boolean
function isReservedEvent (event: string): boolean